package weifei.live.simulation.service;

import com.auth0.jwt.JWT;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import weifei.live.simulation.entity.User;


@Service
public class UserService
{
    private final User dao_user = new User();



    public Integer getUserIDByToken(String token)
    {
        return JWT.decode(token).getClaim("userID").asInt();
    }


    public User getUserByToken(String token)
    {
        var user_id = JWT.decode(token).getClaim("userID").asInt();
        if (user_id == null)
            return null;
        return this.getUserByID(user_id);
    }


    public User getUserByID(int userId)
    {
        QueryWrapper<User> qw_user = new QueryWrapper<>();
        qw_user.eq(User.Column.ID.getName(), userId);
        return this.dao_user.selectOne(qw_user);
    }


}


